#include "StdAfx.h"
#include "TimeTable.h"
#include "Utilities.h"


TimeTable::TimeTable(void)
    : m_week(0)
{
}


TimeTable::~TimeTable(void)
{
}


int TimeTable::ReadConfig(const BYTE* config)
{
    const BYTE* pConf = config;
    for (int day=0; day<7; day++)
    {
        pConf += m_table[day].ReadConfig(pConf);
    }
    m_week = *(long*)pConf;
    return (pConf-config+sizeof(long));
}


int TimeTable::SaveConfig(BYTE* config)
{
    BYTE* pConf = config;
    for (int day=0; day<7; day++)
    {
        pConf += m_table[day].SaveConfig(pConf);
    }
    *(long*)pConf = m_week;
    return (pConf-config+sizeof(long));
}


UserStatus TimeTable::HasToStop(SYSTEMTIME& st)
{
    return m_table[Day(st)].HasToStop(st);
}


UserStatus TimeTable::HasToStop(int day, CurrentTimes& ct)
{
    UserStatus b = CanContinue;
    if (ct.m_week > m_week)
        b = WeekExceeded;
    if (b == CanContinue)
    {
        if ((m_table[day].Time() == 0) || (ct.m_days[day] > m_table[day].Time()))
        b = DayExceeded;
    }
    return b;
}

int TimeTable::TimeRemainsSchedule(SYSTEMTIME& st)
{
    return m_table[Day(st)].TimeRemainsSchedule(st);
}
